package com.ruoyi.project.search.viewInStockHistroy.controller;

import java.util.List;

import com.ruoyi.project.search.viewInStockHistroy.domain.ViewInStockHistory;
import com.ruoyi.project.search.viewInStockHistroy.service.IViewInStockHistoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库单据历史Controller
 * 
 * @author ruoyi
 * @date 2023-08-29
 */
@Controller
@RequestMapping("/viewInStockHistroy/viewInStockHistroy")
public class ViewInStockHistoryController extends BaseController
{
    private String prefix = "/search";

    @Autowired
    private IViewInStockHistoryService viewInStockHistoryService;

    @GetMapping()
    public String viewInStockHistroy()
    {
        return prefix + "/viewInStockHistroy";
    }

    /**
     * 查询入库单据历史列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewInStockHistory viewInStockHistory)
    {
        startPage();
        List<ViewInStockHistory> list = viewInStockHistoryService.selectViewInStockHistoryList(viewInStockHistory);
        return getDataTable(list);
    }

    /**
     * 导出入库单据历史列表
     */
    @Log(title = "入库单据历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewInStockHistory viewInStockHistory)
    {
        List<ViewInStockHistory> list = viewInStockHistoryService.selectViewInStockHistoryList(viewInStockHistory);
        ExcelUtil<ViewInStockHistory> util = new ExcelUtil<ViewInStockHistory>(ViewInStockHistory.class);
        return util.exportExcel(list, "入库单据历史数据");
    }

    /**
     * 新增入库单据历史
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存入库单据历史
     */
    @Log(title = "入库单据历史", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewInStockHistory viewInStockHistory)
    {
        return toAjax(viewInStockHistoryService.insertViewInStockHistory(viewInStockHistory));
    }

    /**
     * 修改入库单据历史
     */
    @GetMapping("/edit/{stockinId}")
    public String edit(@PathVariable("stockinId") String stockinId, ModelMap mmap)
    {
        ViewInStockHistory viewInStockHistory = viewInStockHistoryService.selectViewInStockHistoryByStockinId(stockinId);
        mmap.put("viewInStockHistory", viewInStockHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存入库单据历史
     */
    @Log(title = "入库单据历史", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewInStockHistory viewInStockHistory)
    {
        return toAjax(viewInStockHistoryService.updateViewInStockHistory(viewInStockHistory));
    }

    /**
     * 删除入库单据历史
     */
    @Log(title = "入库单据历史", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewInStockHistoryService.deleteViewInStockHistoryByStockinIds(ids));
    }
}
